package com.android.example.myapplication;

import android.os.Bundle;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.Map;

public class Appread extends AppCompatActivity {
    private TextView tv_app;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.appread);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        tv_app = findViewById(R.id.tv_app);
        readAppMemory();
    }

    // 读取全局内存中保存的变量信息
    private void readAppMemory() {
        String desc = "全局内存中保存的信息如下：";
        // 获取当前应用的Application实例
        MainApplication app = MainApplication.getInstance();
        // 获取Application实例中保存的映射全局变量
        Map<String, String> mapParam = app.mInfoMap;
        // 遍历映射全局变量内部的键值对信息
        for (Map.Entry<String, String> item_map : mapParam.entrySet()) {
            desc = String.format("%s\n　%s的取值为%s",
                    desc, item_map.getKey(), item_map.getValue());
        }
        if (mapParam.size() <= 0) {
            desc = "全局内存中保存的信息为空";
        }
        tv_app.setText(desc);
    }
}